package com.wgc.goods.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wgc.entity.PageResult;
import com.wgc.entity.Result;
import com.wgc.entity.StatusCode;
import com.wgc.goods.domain.Spec;
import com.wgc.goods.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 商品规格
 */
@RestController
@RequestMapping("/Spec")
public class SpecController {
    @Autowired
    private SpecService iSpecService;

    /**
     * 查询全部
     */
    @RequestMapping("/selectAll")
    public Result<List<Spec>> selectAll() {
        return new Result<>("查询成功", iSpecService.selectAll());
    }

    /**
     * 插入
     */
    @RequestMapping("/insert")
    public Result<Integer> insert(@RequestBody Spec spec) {
        iSpecService.insert(spec);
        return new Result<>("插入成功");
    }

    /**
     * 更新数据
     */
    @RequestMapping("/update")
    public Result<Integer> update(@RequestBody Spec spec) {
        iSpecService.update(spec);
        return new Result<>("更新成功");
    }

    /**
     * 删除数据
     */
    @RequestMapping("/delete")
    public Result<Integer> delete(@RequestParam String ids) {
        iSpecService.delete(ids);
        return new Result<>("删除成功");
    }
    /**
     * 条件查询
     */
    @RequestMapping("/selectList")
     public Result<List<Spec>> selectList(@RequestBody Spec spec) {
        return new Result<>("条件查询成功", iSpecService.selectList(spec));
    }
    /**
     * 分页查询
     */
@RequestMapping("/search")
     public Result<List<Spec>> search(@RequestParam(defaultValue = "1")  Integer page,
                                      @RequestParam(defaultValue = "10") Integer size)  {
    Page<Spec> pageList =iSpecService.findPage(page,size);
    PageResult<Spec> pageResult = new PageResult<>(pageList.getTotal(),pageList.getRecords());
        return new Result(true, StatusCode.OK,"查询成功", pageResult);
    }

    /**
     * 品牌名称分页搜索实现
      */
    @GetMapping(value = "/pageList" )
    public Result pageList(@RequestBody Spec spec,@RequestParam(defaultValue = "1")  Integer page, @RequestParam(defaultValue = "10") Integer size){
        Page<Spec> pageList = iSpecService.findPage(spec,page, size);
        PageResult pageResult=new PageResult(pageList.getTotal(),pageList.getRecords());
        return new Result(true,StatusCode.OK,"查询成功",pageResult);
    }

}
